/*
	The Shadow Framework - a complete framework for Real Time Graphics based on OpenGL
    Copyright (C) 2008  Alessandro Martinelli  <alessandro.martinelli@unipv.it>

    This file is part of The Shadow Framework.

    The Shadow Framework is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Shadow Framework is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Shadow Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

package objLoader.math;

public class Vertex2f {

	public float x,y;

	public Vertex2f(double x, double y) {
		this.x = (float)x;
		this.y = (float)y;
	}
	
	public Vertex2f(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public Vertex2f(Vertex2f B) {
		this.x = B.x;
		this.y = B.y;
	}
	
	public Vertex2f() {
	}

	public String toString(){
		return "x:"+x+",y:"+y;
	}
	
	public Vertex2f cloneV(){
		return new Vertex2f(x,y);
	}
	
	public void set(float x,float y){
		this.x=x;
		this.y=y;
	}
	
	public void scale(float sx,float sy){
		this.x*=sx;
		this.y*=sy;
	}
	
	public void set(Vertex2f v){
		x=v.x;
		y=v.y;
	}
	
	public void set(Vertex3f v){
		x=v.x;
		y=v.y;
	}
	
	public float dot(Vertex2f v){
		return v.x*x+v.y*y;
	}
	
	public void normalize(){
		float lengthRec=1/(float)(Math.sqrt(x*x+y*y));
		x*=lengthRec;
		y*=lengthRec;
	}
	
	public void mult(float a){
		x*=a;
		y*=a;
	}
	
	public void add(Vertex2f v){
		x+=v.x;
		y+=v.y;
	}
	
	

	public void subtract(Vertex2f v){
		x-=v.x;
		y-=v.y;
	}
	
	public void setByIndex(int index,float val){
		if(index==0)
			x=val;
		else if(index==1)
			y=val;
	}
	
	public float getByIndex(int index){
		if(index==0)
			return x;
		
		return y;
	}
}
